﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using SimpleGameData.GameObjects.Particles;
using SimpleGameData.MinMax;
using Microsoft.Xna.Framework.Content.Pipeline;

namespace SimpleGameContentProcessors.GameObjects.Particles
{
    /// <summary>
    /// This class will be instantiated by the XNA Framework Content Pipeline
    /// to write the specified data type into binary .xnb format.
    ///
    /// This should be part of a Content Pipeline Extension Library project.
    /// </summary>
    [ContentTypeWriter]
    public class EmitterDataWriter : ContentTypeWriter<EmitterData>
    {
        protected override void Write(ContentWriter output, EmitterData value)
        {
            output.Write(String.IsNullOrEmpty(value.TexturePath) ? String.Empty : value.TexturePath);
            output.Write(value.EmitterPosition);
            output.Write(value.ParticleCount);
            output.Write(value.ParticleMaxSpawnCount);
            output.Write(value.IsRotationDirectionRandom);
            output.Write(value.IsRotationClockwise);
            output.WriteObject<MinMaxFloat>(value.EmissionAngle);
            output.WriteObject<MinMaxFloat>(value.LifeMinMax);
            output.WriteObject<MinMaxFloat>(value.VelocityMinMax);
            output.WriteObject<MinMaxFloat>(value.AccelerationMinMax);
            output.WriteObject<MinMaxFloat>(value.RotationMinMax);
            output.WriteObject<MinMaxFloat>(value.RotationSpeedMinMax);
            output.WriteObject<MinMaxFloat>(value.ScaleMinMax);
            output.WriteObject<MinMaxFloat>(value.ScaleShiftMinMax);
            output.WriteObject<MinMaxFloat>(value.ColorRedStartMinMax);
            output.WriteObject<MinMaxFloat>(value.ColorRedEndMinMax);
            output.WriteObject<MinMaxFloat>(value.ColorGreenStartMinMax);
            output.WriteObject<MinMaxFloat>(value.ColorGreenEndMinMax);
            output.WriteObject<MinMaxFloat>(value.ColorBlueStartMinMax);
            output.WriteObject<MinMaxFloat>(value.ColorBlueEndMinMax);
            output.WriteObject<MinMaxFloat>(value.AlphaValueStartMinMax);
            output.WriteObject<MinMaxFloat>(value.AlphaValueEndMinMax);
        }

        public override string GetRuntimeReader(
                TargetPlatform targetPlatform)
        {
            return typeof(EmitterDataReader).AssemblyQualifiedName;
        }
    }
}
